import {
  ConditionUnit,
  getWherePartFromConditionUnits,
  SqlDataType
} from "./SqlUtil";

export function generateDeleteSql(tableName: string, conditionUnits: ConditionUnit[] = []): [string, SqlDataType[]] {
  const sqlHeader: string = `DELETE FROM ${tableName}`;
  if (!conditionUnits || !conditionUnits.length) {
    return [sqlHeader, []]
  }
  const [wherePart, args] = getWherePartFromConditionUnits(conditionUnits);
  const sql = `${sqlHeader} ${wherePart}`
  return [sql, args];
}